namespace Chaliy.Syndication.MediaRss
{
	using System;
	using System.Xml;
	using System.Xml.Schema;
	using System.Xml.Serialization;
    using System.Runtime.Serialization;

	/// <summary>
    /// 	Raitng allows the permissible audience to be declared. If this element is not included, it assumes that no restrictions are necessary.
	/// </summary>
    [XmlRoot("category", Namespace = Namespaces.MediaRssPrivate)]
    public sealed class MediaCategory : IXmlSerializable
    {
    	/// <summary>
        /// 	Get or set the scheme of the category, which is the URI that identifies the categorization scheme. It is an optional attribute. If this attribute is not included, the default scheme is 'http://search.yahoo.com/mrss/category_schema'.
    	/// </summary>
        public string Scheme
        {
            get;
            set;
        }
            
        /// <summary>
        ///     Get or set the human readable label that can be displayed in end user applications.
        /// </summary>
        public string Label
        {
            get;
            set;
        }

        public string Value
        {
            get;
            set;
        }

        #region IXmlSerializable Members

        XmlSchema IXmlSerializable.GetSchema()
        {
            throw new NotSupportedException(); // TODO Implement
        }

        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            throw new NotSupportedException(); // TODO Implement
        }

        void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            ArgumentUtilities.EnsureArgumentNotNull(writer, "writer");

            // Yahoo! schema is default value, so this is no reason to write it down
            if (MediaCategoryYahooSchema.Identifier
                .Equals(this.Scheme, StringComparison.OrdinalIgnoreCase) == false)
            {
                writer.WriteStringAttribute("scheme", this.Scheme);
            }

            writer.WriteStringAttribute("label", this.Label);

            if (String.IsNullOrEmpty(this.Value) == false)
            {
                writer.WriteValue(this.Value);
            }
        }

        #endregion
    }

}
